<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
	<title>乘阶</title>
<script type="text/javascript">
function calc() {
var n = parseInt(document.getElementById("number").value);
if (!n || n < 1) {
alert('请输入一个大于0的数字。');
return;
}
var result = 1;
 
for (var i = 1; i <= n; i++) {
result *= i;
}
 
document.getElementById("result").innerText = n +'! = ' + result;
}
</script>
</head>
<body>
<input id="number" type="text" /><button onclick="calc()">计算</button>
<br />
<div id="result"></div>
</body>
</html>
